package leetcode.hash;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class Test349 {
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set = new HashSet<>();
        Set<Integer> result = new HashSet<>();
        for (int i : nums1) {
            set.add(i);
        }
        for (int i : nums2) {
            if (set.contains(i)){
                result.add(i);
            }
        }
        int[] data = new int[result.size()];
        int index = 0;
        for (Integer integer : result) {
            data[index++] = integer;
        }
        return data;
    }
}
